package com.bjwl.web.contrlller.branchstore;

import com.bjwl.pojo.Bsadmin;
import com.bjwl.pojo.Partment;
import com.bjwl.pojo.vo.BasicQueryVo;
import com.bjwl.service.PartmentService;
import com.bjwl.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * @Author: dzx
 * @Date:Create：in 2020/5/6 9:25
 * @Description:
 * @Modified By：
 * @Version: 1.0
 */
@Controller
@RequestMapping("/bsPartment")
public class PartmentControllerabc {

    @Autowired
    private PartmentService partmentService;


    @RequestMapping("/addPartment")
    public @ResponseBody boolean addPartment(@RequestBody Partment partment, HttpSession httpSession){
        Bsadmin bsadmin = (Bsadmin) httpSession.getAttribute("bsadmin1");
        partment.setBsid(bsadmin.getBsid());
        return partmentService.addPartment(partment);
    }

    /**
     * 修改前回显
     * @param pmid
     * @param model
     * @return
     */
    @RequestMapping("/editStart")
    public String editStart(Integer pmid, Model model){
        model.addAttribute("partment",partmentService.editStart(pmid));
        return "branch_oa/section-edit";
    }

    /**
     * 修改
     * @param
     * @param
     * @return
     */
    @RequestMapping("/editEnd")
    public @ResponseBody
    boolean editEnd(@RequestBody Partment partment){

        return partmentService.updatePartment(partment);
    }

    @RequestMapping("/deletePartment")
    public @ResponseBody
    boolean deletePartment(@RequestBody Integer pmid){

        return partmentService.deletePartment(pmid);
    }


    @RequestMapping("/findAllPartment")
    public String findAllPartment(BasicQueryVo vo, Model model){
        PageBean<Partment> pageBean = partmentService.findAllPartment(vo);
        model.addAttribute("pageBean",pageBean);
        return "branch_oa/section-list";
    }

}
